package server

import (
	"server5/Bean"
	"server5/Dao"
	"server5/Interface"
	"server5/utils"
)

type UserServiceImpl struct {
	userInfo Bean.UserInfo
}

func NewUserService(userInfo Bean.UserInfo) Interface.IUserService {
	userService := &UserServiceImpl{userInfo:userInfo}
	return userService
}

func (u *UserServiceImpl) UpgradeSoldierLevel(unitType int32)  {
	userInfo := u.userInfo
	switch unitType {
		case utils.Archer:
			if userInfo.ArcherLevel < 3 {
				if userInfo.UserGold >= 100 {
					userInfo.ArcherLevel++
					userInfo.UserGold -= 100
				}
			}
		case utils.Infantry:
		if userInfo.InfantryLevel < 3 {
			if userInfo.UserGold >= 100 {
				userInfo.InfantryLevel++
				userInfo.UserGold -= 100
			}
		}
	}
	Dao.GetUserDao().UpdateUser(userInfo)
}


func (u *UserServiceImpl) UpgradeSkillLevel(SkillType int32)  {
	userInfo := u.userInfo
	switch SkillType {
	case utils.Damage:
		if userInfo.DamageLevel < 3 {
			if userInfo.UserSp >= 1 {
				userInfo.DamageLevel++
				userInfo.UserSp--
			}
		}
	case utils.ReplyHp:
		if userInfo.ReplyHpLevel < 3 {
			if userInfo.UserSp >= 1 {
				userInfo.ReplyHpLevel++
				userInfo.UserSp--
			}
		}
	case utils.CallBoss:
		if userInfo.CallBossLevel < 3 {
			if userInfo.UserSp >= 1 {
				userInfo.CallBossLevel++
				userInfo.UserSp--
			}
		}
	}
	Dao.GetUserDao().UpdateUser(userInfo)
}


